package tspda

import glory.xxd.Utils
import tsCIM.ResultCode
import tsCIM.modelForInterface.Header
import tsCIM.modelForInterface.RequestModel
import tsCIM.modelForInterface.ResultModel
import tsCIM.modelForInterface.Return

class PDAMaterialInfoRequestController {

    def commentService

    def index() {
        def result = ResultModel.getResultModel()
        try {

            def EQPID = params.EQPID ?: ""
            def MACHINENAME = params.MACHINENAME ?: ""
            def body = [EQPID: EQPID]
            Header header = new Header(TRANSACTIONID: Utils.getUUID(), MESSAGENAME: "PDAMaterialInfoRequest", MACHINENAME: MACHINENAME)
            Return aReturn = new Return()
            RequestModel requestModel = new RequestModel(header: header, body: body, aReturn: aReturn)
//            result = commentService.getJsonByTopic2Queue(requestModel,"sendmqname","returnmqname",true,responseXml)
            result = commentService.getJsonByTopic2Queue(requestModel, "jms.topic.PDA.TO.CIM", "jms.queue.CIM.PDA.Send", false, false)
        } catch (Exception e) {
            result.put(ResultModel.ServerErrorFlag, true)
            result.put(ResultModel.Code, ResultCode.SERVER_INTERFACE_ERROR.code)
            result.put(ResultModel.Msg, ResultCode.SERVER_INTERFACE_ERROR.msg)
            result.put(ResultModel.Data, e.getMessage())
        } finally {
            render Utils.getFormatString(result)
        }
    }

    def responseXml = """
<MESSAGE>
<HEADER>
  <TRANSACTIONID>85efce3f-326d-4290-a337-0efc58e1833a</TRANSACTIONID>
  <MESSAGENAME>PDAMaterialInfoResponse</MESSAGENAME>
  <MACHINENAME>WM-2112</MACHINENAME>
  <WORKNO>1</WORKNO>
  <EVENTUSER>CIM</EVENTUSER>
  <EVENTTIME>2019-03-29 16:07:36.165</EVENTTIME>
</HEADER>
<BODY>
  <EQPMATERIALLIST>
    <MATERIALPROP>
      <MATERIALTYPE>AdhesiveFilm</MATERIALTYPE>

    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>LF</MATERIALTYPE>
      <MATERIALMODEL>DB-447</MATERIALMODEL>
      <MATERIALSIZE>DB-447</MATERIALSIZE>
      <BATCH_NO>DB-447</BATCH_NO>
    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>Epoxy</MATERIALTYPE>
      <MATERIALMODEL>DB-447</MATERIALMODEL>
      <THAWING_END_TIME>DB-447</THAWING_END_TIME>
      <THAWING_START_TIME>DB-447</THAWING_START_TIME>
      <BATCH_NO>DB-447</BATCH_NO>
    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>Thimble</MATERIALTYPE>
      <MATERIALSIZE>DB-447</MATERIALSIZE>
    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>SuctionNozzle</MATERIALTYPE>
      <MATERIALSIZE>DB-447</MATERIALSIZE>
    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>AdhesiveFilm</MATERIALTYPE>
    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>AdhesiveFilm</MATERIALTYPE>
    </MATERIALPROP>
    <MATERIALPROP>
      <MATERIALTYPE>AdhesiveFilm</MATERIALTYPE>
    </MATERIALPROP>
  </EQPMATERIALLIST>
  <EQPID>DB-447</EQPID>
</BODY>
<RETURN>
  <RETURNCODE>0</RETURNCODE>
  <RETURNMESSAGE>返回设备物料信息</RETURNMESSAGE>
</RETURN>
</MESSAGE>
    """
}
